package com.ai.image_v1.controller;

/**
 * ClassName:    ImageGenerateController
 * Description:  TODO
 * Author:       yuzx
 * Date:         2025/9/6 14:02
 * Version:      1.0
 **/

import com.ai.image_v1.service.ImageGenerateService;
import com.ai.common.core.controller.BaseController;
import com.ai.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 图片生成控制器
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/image")
public class ImageGenerateController extends BaseController {

    @Autowired
    private ImageGenerateService imageGenerateService;

    /**
     * 根据文字描述生成图片
     */
    @PostMapping("/generate")
    public AjaxResult generateImage(@RequestBody Map<String, String> params) {
        String prompt = params.get("prompt");
        if (prompt == null || prompt.trim().isEmpty()) {
            return AjaxResult.error("请输入图片描述");
        }
        try {
            String imageUrl = imageGenerateService.generateImage(prompt);
            return AjaxResult.success("图片生成成功", imageUrl);
        } catch (Exception e) {
            return AjaxResult.error("图片生成失败: " + e.getMessage());
        }
    }
}
